<template>
  <div class="scheduling_box">
    <a-tabs type="card" v-model:activeKey="activeFormKey" animated>
      <a-tab-pane tab="排产工作台" key="productionSchedulingContent" :forceRender="true">
        <BasicForm @register="registerForm" ref="formRef">
          <template #masterPlanSlot="{ model, field }">
            <!-- <a-input-search
              v-model:value="model[field]"
              placeholder="请选择生产主计划"
              readonly
              :disabled="isDetail"
              @search="masterPlanOpen(model)"
            /> -->
            <a-button class="mgl-15" type="primary" @click="masterPlanOpen(model)">新增需求</a-button>
          </template>
          <template #productionSchedulingSchemeSlot="{ model, field }">
            <a-input-search
              :disabled="isDetail"
              v-model:value="model[field]"
              placeholder="请选择排产方案"
              readonly
              @search="openPsAlwaysScheduling"
            />
          </template>
          <template #formFooter="{ model, field }">
            <a-button class="mgl-15" color="success" @click="clickSchedulingOperation" v-if="hasPermission('ps:ps_planning_scheduling:calculate')"
              >排产作业</a-button
            >
          </template>
        </BasicForm>
      </a-tab-pane>
    </a-tabs>
    <!-- 子表单区域 -->
    <a-tabs type="card" class="my_tabs" v-model:activeKey="activeKey" animated @change="handleChangeTabs">
      <a-tab-pane tab="排产需求" key="psPlanningSchedulingOrderContent" :forceRender="true">
        <JVxeTable
          keep-source
          resizable
          ref="psPlanningSchedulingOrderContent"
          :rowNum="true"
          rowNumKey="srcDocLineNo"
          :loading="psPlanningSchedulingOrderContentTable.loading"
          :columns="psPlanningSchedulingOrderContentTable.columns"
          :dataSource="psPlanningSchedulingOrderContentTable.dataSource"
          :height="550"
          :rowSelection="true"
          :disabled="formDisabled"
          :toolbar="true"
          :toolbarConfig="toolbarConfig"
          :pagination="pagination"
          @removed="removed"
          @pageChange="pageChange"
        >
          <!-- @valueChange="valueChange" -->
          <template #toolbarSuffix>
            <a-form
              layout="inline"
              :model="formState"
              @finish="getList"
              :labelCol="{ span: 8 }"
              style="margin-bottom: 10px"
            >
              <a-form-item label="订单编号">
                <a-input v-model:value="formState.srcDocNo" placeholder="请输入订单编号" allowClear> </a-input>
              </a-form-item>
              <a-form-item label="产品编码">
                <a-input v-model:value="formState.productCode" placeholder="请输入产品编码" allowClear> </a-input>
              </a-form-item>
              <a-form-item label="订单交期">
                <a-range-picker v-model:value="formState.orderDeliveryDate" @change="changeOrderDeliveryDate" :valueFormat="'YYYY-MM-DD HH:mm:ss'" />
              </a-form-item>
              <a-form-item>
                <a-button type="primary" html-type="finish">查询</a-button>
              </a-form-item>
            </a-form>
          </template>
          <template #srcDocTypeSlot="props">
            {{ props.row.srcDocType === 1 ? '计划订单' : props.row.srcDocType === 2 ? '销售订单' : '生产订单' }}
          </template>
          <template #action="props">
            <a @click="handleEdit(props.row)">编辑</a>
            <a-divider type="vertical" v-if="hasPermission('ps:scheduling:delete')" />
            <a-popconfirm title="确定删除吗？" @confirm="handleDelete([props.row])" v-if="hasPermission('ps:scheduling:delete')">
              <a>删除</a>
            </a-popconfirm>
          </template>
        </JVxeTable>
      </a-tab-pane>
      
      <a-tab-pane tab="采购预警" key="prAlarmList" :forceRender="true">
        <JVxeTable
          keep-source
          resizable
          ref="prAlarmList"
          :loading="prAlarmListTable.loading"
          :columns="prAlarmListTable.columns"
          :dataSource="prAlarmListTable.dataSource"
          :height="550"
          :disabled="formDisabled"
          :pagination="pagination3"
          :toolbar="true"
          :toolbarConfig="{slots: ['prefix', 'suffix'],btns:[]}"
          @removed="removed"
          @pageChange="pageChange3"
        >
        <template #toolbarSuffix>
          <a-form
              layout="inline"
              :model="formState"
              @finish="getList3"
              :labelCol="{ span: 8 }"
              style="margin-bottom: 10px"
            >             
              <a-form-item>
                <a-button type="primary" html-type="finish">刷新</a-button>
              </a-form-item>
            </a-form>
          </template>
        </JVxeTable>
      </a-tab-pane>
      
      <a-tab-pane tab="排产日志" key="productionSchedulingLog" :forceRender="true">
        <JVxeTable
          keep-source
          resizable
          ref="productionSchedulingLog"
          :loading="productionSchedulingLogTable.loading"
          :columns="productionSchedulingLogTable.columns"
          :dataSource="productionSchedulingLogTable.dataSource"
          :height="550"
          :disabled="formDisabled"
          :pagination="pagination2"
          :toolbar="true"
          :toolbarConfig="{slots: ['prefix', 'suffix'],btns:[]}"
          @removed="removed"
          @pageChange="pageChange2"
        >
        <template #toolbarSuffix>
          <a-form
              layout="inline"
              :model="formState"
              @finish="getList2"
              :labelCol="{ span: 8 }"
              style="margin-bottom: 10px"
            >             
              <a-form-item>
                <a-button type="primary" html-type="finish">刷新</a-button>
              </a-form-item>
            </a-form>
          </template>
          <template #statusSlot="props">
            {{ props.row.status === 0 ? '运行中' : props.row.status === 1 ? '成功' : '失败' }}
          </template>
        </JVxeTable>
      </a-tab-pane>
      
    </a-tabs>
    <!-- 方案选择 -->
    <psAlwaysSchedulingSelectModel @register="psAlwaysSchedulingRegModal" @getSelectResult="psAlwaysSchedulinghandleSuccess" v-bind="getBindValue">
    </psAlwaysSchedulingSelectModel>
    <!-- 订单选择 -->
    <!-- <planOrerResultSelectModel @register="planOrderResultRegModal" @getSelectResult="planOrderResultHandleSuccess" v-bind="getBindValue" /> -->
    <!-- MPS生产主计划列表 -->
    <mpsSelectModel @register="mpsItemRegModal" @getSelectResult="mpsItemhandleSuccess" :multiple="true" v-bind="getBindValue" />
    <!-- 订单选择 -->
    <orderSelectModel @register="orderRegModal" @getSelectResult="orderhandleSuccess" :multiple="true" v-bind="getBindValue" />
    <!-- MRP计算结果 -->
    <mrpResultModal @register="registerMrpResultModal" @getSelectResult="mrpResulthandleSuccess" :multiple="true" />
    <!-- 选择MO列表 -->
    <finalAssemblyPlanOrderSelectModel @register="registerMOListModal" @getSelectResult="MOListhandleSuccess" :multiple="true" />
    <!-- 选择总装排产计划 -->
    <arrangementPlansSelectModel
      @register="arrangementPlanRegModal"
      @getSelectResult="arrangementPlanhandleSuccess"
      :multiple="true"
      v-bind="getBindValue"
    />
    <!-- 料品 -->
    <materialSelectModel @register="materialRegModal" @getSelectResult="materialhandleSuccess" v-bind="getBindValue"></materialSelectModel>
    <!-- 子表编辑界面 -->
    <psPlanningSchedulingEdit @register="registerPlanningSchdulingEdit" @success="getSchedulingList" />
  </div>
</template>

<script lang="ts" setup>
import { ref, computed, unref, reactive, onMounted, inject } from 'vue';
import { BasicModal, useModalInner, useModal } from '/@/components/Modal';
import { BasicForm, useForm } from '/@/components/Form/index';
import { JVxeTable } from '/@/components/jeecg/JVxeTable';
import { useJvxeMethod } from '/@/hooks/system/useJvxeMethods';
import {
  formSchema,
  psPlanningSchedulingOrderContentColumns,
  simulatedResultColumns,
  productionSchedulingLogColumns,
  prAlarmListColumns,
} from './PsPlanningScheduling.data.ts';
import {
  saveOrUpdate,
  psPlanningSchedulingOrderContentList,
  psPlanningSchedulingAvailableResourcesList,
  distributePlan,
  getMpsItemByMainIds,
  getArrangementItemByMainIds,
  // getSimulatedScheduling,
  calculate,
  getPsProductionArrangementImitatePlansAll,
  schedulingList,
  gerProductionSchedulingLogList,
  gerPRAlarmList,
  schedulingDel,
} from './PsPlanningScheduling.api';
import { VALIDATE_FAILED } from '/@/utils/common/vxeUtils';
import psAlwaysSchedulingSelectModel from '/@/views/components/psAlwaysSchedulingSelectModel.vue';
import orderSelectModel from '/@/views/components/orderSelectModel.vue';
// import planOrerResultSelectModel from '/@/views/components/planOrderResultSelectModel.vue';
import { useMessage } from '/@/hooks/web/useMessage';
import mpsSelectModel from '/@/views/components/mpsSelectModel.vue';
import arrangementPlansSelectModel from '/@/views/components/arrangementPlansSelectModel.vue';
import mrpResultModal from '/@/views/components/mrpResultModal.vue';
import finalAssemblyPlanOrderSelectModel from '/@/views/components/finalAssemblyPlanOrderSelectModel.vue';
import materialSelectModel from '/@/views/components/materialSelectModel.vue';
import psPlanningSchedulingEdit from './components/PsPlanningSchedulingEdit.vue';
import { useLoading } from '/@/components/Loading';
import { usePermission } from '/@/hooks/web/usePermission';
const { hasPermission } = usePermission();
const [openFullLoading, closeFullLoading] = useLoading({
  tip: '正在进行模拟排产...',
});
// 分页器
const pagination = reactive({
  current: 1,
  pageSize: 10,
  total: 0,
});
const pagination2 = reactive({
  current: 1,
  pageSize: 10,
  total: 0,
});
const pagination3 = reactive({
  current: 1,
  pageSize: 10,
  total: 0,
});
// 工具栏的按钮配置
const toolbarConfig = reactive({
  // add 新增按钮；remove 删除按钮；clearSelection 清空选择按钮
  btn: ['remove', 'clearSelection'],
  // btn: [],
});
// Emits声明
const emit = defineEmits(['register', 'success']);
const isUpdate = ref(true);
const isDetail = ref<boolean>(false);
const formDisabled = ref(false);
const refKeys = ref(['psPlanningSchedulingOrderContent']);
const activeKey = ref('psPlanningSchedulingOrderContent');
const activeFormKey = ref('productionSchedulingContent');
const psPlanningSchedulingOrderContent = ref();
const productionSchedulingLogContent = ref();
const tableRefs = {
  psPlanningSchedulingOrderContent,
  productionSchedulingLogContent,
};
interface Props {
  // planId: number | string;
}
const openPicker = ref(true);
const operatFormItem = ref<any>(null);
const propsData = defineProps<Props>();
const psPlanningSchedulingOrderContentTable = reactive({
  loading: false,
  dataSource: <Array<any>>[],
  columns: psPlanningSchedulingOrderContentColumns,
});
const productionSchedulingLogTable = reactive({
  loading: false,
  dataSource: <Array<any>>[],
  columns: productionSchedulingLogColumns,
});
const prAlarmListTable = reactive({
  loading: false,
  dataSource: <Array<any>>[],
  columns: prAlarmListColumns,
});
// 子表 - 模拟结果
const simulatedResultTable = reactive({
  loading: false,
  dataSource: <Array<any>>[],
  columns: simulatedResultColumns,
});

//表单配置
const [registerForm, { setProps, resetFields, setFieldsValue, getFieldsValue, validate, validateFields }] = useForm({
  labelWidth: 100,
  schemas: formSchema,
  showActionButtonGroup: false,
  baseColProps: {
    xs: 6,
    sm: 6,
    md: 6,
    lg: 6,
    xl: 6,
    xxl: 6,
  },
});
const $message = useMessage();
//方法配置
const [handleSubmit, requestSubTableData, formRef] = useJvxeMethod(classifyIntoFormData, tableRefs, activeKey, refKeys);
onMounted(() => {
  getSchedulingList();
});
async function reset() {
  await resetFields();
  activeKey.value = 'psPlanningSchedulingOrderContent';
  psPlanningSchedulingOrderContentTable.dataSource = [];
  simulatedResultTable.dataSource = [];
}
const handleChangeTabs = async (activeKey) => {
  if (activeKey === 'productionSchedulingLog') {
    await getSchedulingListTwo();
  } else if (activeKey === 'prAlarmList') {
    await getPrAlarmList();
  }
};
function classifyIntoFormData(allValues) {
  let main = Object.assign({}, allValues.formValue);
  return {
    ...main, // 展开
    psPlanningSchedulingOrderContentList: allValues.tablesValue[0].tableData,
  };
}
let index: number | null = null;
//打开选择料品
function handleView(props) {
  index = props.params.$rowIndex;
  openMaterialModal(true, {
    isUpdate: false,
    showFooter: true,
  });
}
const [materialRegModal, { openModal: openMaterialModal }] = useModal();
const [psAlwaysSchedulingRegModal, { openModal: openpsAlwaysSchedulingModal }] = useModal();
// const [planOrderResultRegModal, { openModal: openPlanOrderResultModal }] = useModal();
const [mpsItemRegModal, { openModal: openMpsListModal }] = useModal();
const [orderRegModal, { openModal: openOrderListModal }] = useModal();
const [arrangementPlanRegModal, { openModal: openArrangementPlanModal }] = useModal();
const [registerMrpResultModal, { openModal: openMrpResultModal }] = useModal();
const [registerMOListModal, { openModal: openMOListModal }] = useModal();
const [registerPlanningSchdulingEdit, { openModal: openPlanningSchdulingEditModal }] = useModal();

const getBindValue = Object.assign({}, '');
const formState = reactive({
  srcDocNo: '',
  productCode: '',
  orderDeliveryDate: [],
});

function openPsAlwaysScheduling() {
  openpsAlwaysSchedulingModal(true, {
    isUpdate: false,
    showFooter: true,
    type: 1,
  });
}
// 编辑子表
function handleEdit(data) {
  openPlanningSchdulingEditModal(true, data);
}
// 根据id删除一条子表
async function handleDelete(row) {
  let params = row.map((item) => {
    return item.id;
  });
  await schedulingDel(params);
  getSchedulingList();
}
function masterPlanOpen(model) {
  switch (model.billType) {
    case 1:
      openMrpResultModal(true, {
        isUpdate: true,
        showFooter: false,
      });
      break;
    case 2:
      openOrderListModal(true, {
        isUpdate: false,
        showFooter: true,
      });
      break;
    case 3:
      openMOListModal(true, {
        isUpdate: false,
        showFooter: true,
      });
      break;
    default:
      $message.createMessage.warn('请先选择计划方法');
      break;
  }
}
// 特殊处理 修改交期的提交
function valueChange(item) {
  saveOrUpdate(item.row, true);
}
async function schedulingOrderContentTableAdded(rows) {
  rows.map((item) => delete item.id);
  //添加完成
  let res = await saveOrUpdate(rows, false);
}
function changeOrderDeliveryDate(arr) {
  if (arr && arr.length > 0) {
    formState.orderDeliveryDateStats = arr[0];
    formState.orderDeliveryDateEnd = arr[1];
  } else {
    delete formState.orderDeliveryDateStats;
    delete formState.orderDeliveryDateEnd;
  }
}
function removed(row) {
  handleDelete(row.deleteRows);
}
// 排产工作台详情列表
async function getSchedulingList() {
  // 处理分页参数
  let tempParams = {
    column: 'createTime',
    order: 'desc',
    pageNo: pagination.current,
    pageSize: pagination.pageSize,
  };
  const params = Object.assign(tempParams, formState);
  delete params.orderDeliveryDate;
  let res = await schedulingList(params);
  psPlanningSchedulingOrderContentTable.dataSource = psPlanningSchedulingOrderContent.value!.getTableData();
  psPlanningSchedulingOrderContentTable.dataSource = res.records;
  pagination.total = res.total;
}
async function getSchedulingListTwo() {
  // 处理分页参数
  let tempParams = {
    column: "createTime",
    order: "desc",
    pageNo: pagination2.current,
    pageSize: pagination2.pageSize,
  };
  let res = await gerProductionSchedulingLogList(tempParams);
  // productionSchedulingLogTable.dataSource = psPlanningSchedulingOrderContent.value!.getTableData();
  productionSchedulingLogTable.dataSource = res.records;
  pagination2.total = res.total;
}
async function getPrAlarmList() {
  // 处理分页参数
  let tempParams = {
    column: "createTime",
    order: "desc",
    pageNo: pagination3.current,
    pageSize: pagination3.pageSize,
  };
  let res = await gerPRAlarmList(tempParams);
  prAlarmListTable.dataSource = res.records;
  pagination3.total = res.total;
}
// 当前页数归类为1 后调列表数据
function getList() {
  pagination.current = 1;
  getSchedulingList();
}
function pageChange({ current, pageSize }) {
  pagination.current = current;
  pagination.pageSize = pageSize;
  getSchedulingList();
}
function pageChange2({ current, pageSize }) {
  pagination2.current = current;
  pagination2.pageSize = pageSize;
  getSchedulingListTwo();
}
function pageChange3({ current, pageSize }) {
  pagination3.current = current;
  pagination3.pageSize = pageSize;
  getPrAlarmList();
}
function getList3() {
  pagination3.current = 1;
  getPrAlarmList();
}
function getList2() {
  pagination2.current = 1;
  getSchedulingListTwo();
}
function dateChange(date) {}
//料品选择回写
function materialhandleSuccess(val, values) {
  psPlanningSchedulingOrderContentTable.dataSource = psPlanningSchedulingOrderContent.value!.getTableData();
  psPlanningSchedulingOrderContentTable.dataSource[index].productName = val[0].label;
  psPlanningSchedulingOrderContentTable.dataSource[index].productCode = val[0].item.code;
  psPlanningSchedulingOrderContentTable.dataSource[index].productId = val[0].value;
  // 传递数据给后台
  saveOrUpdate(psPlanningSchedulingOrderContentTable.dataSource[index], true);
}
// mps筛选回写
function mpsItemhandleSuccess(val, values) {
  let ids = values.toString();
  let codeArr = [];
  val.forEach((v) => {
    codeArr.push(v.item.mainPlanCode);
  });
  setFieldsValue({
    billCode: codeArr.toString(),
    masterPlanId: ids,
  });
  getMpsDetail(ids);
}
// 获取Mps详情
async function getMpsDetail(ids) {
  let res = await getMpsItemByMainIds({
    ids: ids,
  });
  res.map((item) => {
    item.orderRowNum = item.rowNum;
    item.orderCenterId = item.id;
    delete item.id;
  });
  psPlanningSchedulingOrderContentTable.dataSource = psPlanningSchedulingOrderContent.value!.getTableData();
  psPlanningSchedulingOrderContentTable.dataSource = res;
}
// mrp运算结果筛选
async function mrpResulthandleSuccess(val, values) {
  const codeArr: Array<string> = [];
  const items: any[] = [];
  let data = getFieldsValue();    
  val.forEach((v) => {
    codeArr.push(v.item.billCode);
    const item = {
      srcDocId: v.item.id,
      srcDocNo: v.item.billCode,
      srcDocLineNo: v.item.rowNum,
      srcDocType : data.billType,
      productCode: v.item.materialCode,
      productId: v.item.materialId,
      productName: v.item.materialName,
      orderDeliveryDate: v.item.demandDate,
      orderQuantity: v.item.orderQuantity,
      lastEndDischarge: '',
      totalProduction: v.item.adjustedMrpQuantity,
      actualProductionScheduling: '',
      orderNo: v.item.orderBillCode,
      orderRowNo: v.item.orderRowNumber
    };
    items.push(item);
  });
  setFieldsValue({
    billCode: codeArr.toString(),
    masterPlanId: values.toString(),
  });
  // psPlanningSchedulingOrderContent.value.addRows(items);
  // // 触发新增方法
  await schedulingOrderContentTableAdded(items);
  await getSchedulingList();
}
// MO订单列表选择
async function MOListhandleSuccess(val, values) {
  const codeArr: Array<string> = [];
  const items: any[] = [];
  let data = getFieldsValue();    
  val.forEach((v) => {
    codeArr.push(v.item.moNo);
    const item = {
      srcDocNo: v.item.moNo,
      srcDocLineNo: 10,
      srcDocType: data.billType,
      productCode: v.item.partCode,
      productName: v.item.partName,
      orderDeliveryDate: v.item.plannedStartDate.substr(0, 10),
      orderQuantity: v.item.orderQuantity,
      actualProductionScheduling: v.item.unFinishedQuantity,
    };
    items.push(item);
  });
  setFieldsValue({
    billCode: codeArr.toString(),
    masterPlanId: values.toString(),
  });
  // psPlanningSchedulingOrderContent.value.addRows(items);
  // 触发新增方法
  await schedulingOrderContentTableAdded(items);
  await getSchedulingList();
}
// 总装排产计划回写
function arrangementPlanhandleSuccess(val, values, type) {
  let ids = values.toString();
  let codeArr = [];
  val.forEach((v) => {
    codeArr.push(v.item.schedulingCode);
  });
  setFieldsValue({
    billCode: codeArr.toString(),
    masterPlanId: ids,
  });
  getArrangementDetail(ids);
}
// 获取总装排产详情
async function getArrangementDetail(ids) {
  let res = await getArrangementItemByMainIds({
    ids: ids,
  });
  res.map((item) => {
    item.orderRowNum = item.rowNum;
    item.orderCenterId = item.id;
    delete item.id;
  });
  psPlanningSchedulingOrderContentTable.dataSource = psPlanningSchedulingOrderContent.value!.getTableData();
  psPlanningSchedulingOrderContentTable.dataSource = res;
}
//订单回写
async function orderhandleSuccess(val, values, type) {
  psPlanningSchedulingOrderContentTable.dataSource = psPlanningSchedulingOrderContent.value!.getTableData();
  let tempArr = [];
  let codeArr = [];
  let data = getFieldsValue();    
  val.forEach((v) => {
    codeArr.push(v.item.billCode);
    tempArr.push({
      mrpResultCode: '',
      srcDocId: v.item.id,
      srcDocNo: v.item.billCode,
      srcDocLineNo: v.item.rowNum,
      srcDocType : data.billType,
      productCode: v.item.materialCode,
      productId: v.item.materialId,
      productName: v.item.materialName,
      orderDeliveryDate: v.item.orderDeliveryDate,
      orderQuantity: v.item.orderQuantity,
      lastEndDischarge: '',
      totalProduction: '',
      orderRowNo: v.item.rowNum,
      orderNo: v.item.billCode,
      // 2023.7.18 要求本次需排产数量取值 订单数量-已排产数量
      actualProductionScheduling: v.item.orderQuantity - v.item.productQuantity,
      // 2023.7.18要求未排数量改名为已排数量，订单回写时取已排数量的值
      unProductionScheduling: v.item.productQuantity,
    });
  });
  setFieldsValue({
    billCode: codeArr.toString(),
    masterPlanId: values.toString(),
  });
  // psPlanningSchedulingOrderContentTable.dataSource = tempArr;
  // 触发新增方法
  await schedulingOrderContentTableAdded(tempArr);
  await getSchedulingList();
}

function psAlwaysSchedulinghandleSuccess(val) {
  setFieldsValue({
    productionSchedulingScheme: val[0].label,
    productionSchedulingSchemeId: val[0].value,
  });
}
// 下发计划
const clickDistributePlan = async () => {
  await distributePlan({
    id: propsData.planId,
  }).catch((err) => {
  });
  //刷新列表
  emit('success');
};
// 模拟排产
const clickSimulatedScheduling = async () => {
  openFullLoading();
  try {
    let data = getFieldsValue();
    // 模拟排产
    // await getSimulatedScheduling({
    //   id: data.id.toString(),
    // });
    await getAllPlansList(data);
  } finally {
    closeFullLoading();
  }
};
// 排产作业按钮
async function clickSchedulingOperation() {
  let values = await validateFields(['productionSchedulingScheme']);
  openFullLoading();
  try {
    let data = getFieldsValue();
    let tempIdArr = [];
    await calculate({
      productionSchedulingSchemeId: data.productionSchedulingSchemeId,
    });
    closeFullLoading();
  } finally {
    closeFullLoading();
  }
}
// 新增按钮
function clickSchedulingTableAdd() {
  const records: any[] = [];
  let tempObj = {
    mrpResultCode: "",
    srcDocId: "",
    srcDocNo: "",
    srcDocType : "",
    srcDocLineNo: "",
    productCode: "",
    productName: "",
    orderDeliveryDate: "",
    orderQuantity: "",
    lastEndDischarge: "",
    totalProduction: "",
    actualProductionScheduling: "",
    unProductionScheduling: "",
  };
  records.push(tempObj);
  psPlanningSchedulingOrderContent.value.addRows(records);
}
// 删除按钮
async function clickSchedulingTableDel() {
  // 获取选中的列
  let selectData = psPlanningSchedulingOrderContent.value.getSelectionData();
  if (selectData.length > 0) {
    let ids = [];
    selectData.forEach((item) => {
      ids.push(item.id);
    });
    // 删除数据库数据
    await schedulingDel(ids);
    // 删除界面数据
    // psPlanningSchedulingOrderContent.value.removeSelection();
    await getSchedulingList();
  } else $message.createMessage.warn('请先选择数据');
}
// 获取模拟排产-全部列表
async function getAllPlansList(data) {
  let res = await getPsProductionArrangementImitatePlansAll({
    id: data.id.toString(),
  });
  // 请求成功就将返回的数据返回给模拟排产table
  simulatedResultTable.dataSource = simulatedResultRef.value!.getTableData();
  simulatedResultTable.dataSource = res;
  //刷新列表
  emit('success');
}
</script>


<style lang="less" scoped>
@import './index.css';
:deep(.ant-form-inline .ant-form-item) > .ant-form-item-label {
  flex: auto;
}
/** 时间和数字输入框样式 */
:deep(.ant-input-number) {
  width: 100%;
}

:deep(.ant-calendar-picker) {
  width: 100%;
}

.mgl-15 {
  margin-left: 15px;
}

.scheduling_box {
  padding: 20px 10px;
  background-color: #fff;
}

:deep(.my_tabs .ant-tabs-nav-wrap) {
  // flex: 0.1 !important;
}
</style>
